<?php
declare (strict_types = 1);

namespace app\command;

use app\data\components\SqlAction;
use think\App;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Dict extends Command
{
  protected function configure()
  {
    // 指令配置
    $this->setName('dict')
      ->addArgument('check',Argument::OPTIONAL,"检查依赖环境")
      ->setDescription('生成数据字典');
  }

  protected function execute(Input $input, Output $output)
  {
    $check = empty($input->getArgument('check')) ? '' : trim($input->getArgument('check'));
    if($check){
      $node = shell_exec("node -v");
      $npm = shell_exec("npm -v");
      $yarn = shell_exec("yarn -v");
      if(empty($node)){
        $output->writeln('node 不可用');
        return;
      }
      if(empty($npm)){
        $output->writeln('npm 不可用');
        return;
      }
      if(empty($yarn)){
        $output->writeln('yarn 不可用');
        return;
      }
      $output->writeln('run environment ok');
      return;
    }
    // 指令输出
    $dict = new SqlAction();
    $dict->run();
    $dictDir = App::getInstance()->getRootPath().'public'.DIRECTORY_SEPARATOR.'dict';
    //$result = shell_exec("cd {$dictDir}; yarn build .");
    //echo $result;
    exit();
  }
}
